#include <stdio.h>
#include <stdlib.h>

typedef char ElemType;

typedef struct Inode {
	int tag;
	union {
		ElemType data;
		struct Inode *head;

	} val;
	int depth;
	struct Inode *tail;
} GLNode;

GLNode *CreateGL(char *&p) {
	GLNode *g;
	char a = *p++;
	int depth = 0;
	if (a != '\n') {
		g = (GLNode *)malloc(sizeof(GLNode));
		if (a == '(') {
			depth++;
			g->depth = depth;
			g->tag = 1;
			g->val.head = CreateGL(p);
		} else if (a == ')') {
			depth--;
			g = NULL;
		} else {
			g->tag = 0;
			g->val.data = a;
		}
	} else {
		g = NULL;
	}
	a = *p++;
	if (g != NULL) {
		if (a == ',')
			g->tail = CreateGL(p);
		else
			g->tail = NULL;
	}
	return g;
}

int GLDepth(GLNode *g) {
	GLNode *p;
	int maxg = 0, dep;
	if (g->tag == 0)
		return 0;
	p = g->val.head;
	if (p == NULL)
		return 1;
	while (p != NULL) {
		if (p->tag == 1) {
			dep = GLDepth(p);
			if (dep > maxg)
				maxg = dep;
		}
		p = p->tail;
	}
	return (maxg + 1);
}

int main() {
	char s[100];
	gets(s);
	char *p = s;
	int depth;
	GLNode *q;
	q = CreateGL(p);
	int n;
	scanf("%d", &n);
	q = q->tail;
	while (q != NULL) {
		printf("%d", q->depth);
		if (q->depth == n) {
			printf("%c", q->val);
		}
		q = q->tail;
	}

	return 0;
}